# encoding: UTF-8

require_relative 'treasure_kind'
require_relative 'treasure'
  
module Napakalaki
  class BadStuff
    attr_reader :text, :levels, :n_visible_treasures, :n_hidden_treasures, 
      :death, :specific_hidden_treasures, :specific_visible_treasures    
    
    def initialize (a_text, some_level, some_visible_treasures = 0, 
        some_hidden_treasures = 0, some_specific_visible_treasures, 
        somespecific_hidden_treasures, death)
      @text = a_text
      @levels = some_level
      @n_visible_treasures = some_visible_treasures
      @n_hidden_treasures = some_hidden_treasures      
      @specific_hidden_treasures = somespecific_hidden_treasures
      @specific_visible_treasures = some_specific_visible_treasures
      @death = death
    end

    #Métodos de clase CONSTRUCTORES
    def self.new_level_number_of_treasures (t, l, nVisible, nHidden)
      self.new(t, l, nVisible, nHidden, Array.new, Array.new, false)
    end
        
    def BadStuff.new_level_specific_treasures (t, l, v, h)    
      self.new(t, l, 0, 0, v, h, false)
    end
        
    def BadStuff.new_death (t, death)
      self.new(t, 0, 0, 0, Array.new, Array.new, death)
    end
          

    public #METODOS PUBLICOS    
    def is_empty
      if ((n_visible_treasures == 0) && (n_hidden_treasures == 0)
          (specific_hidden_treasures.empty?) && (specific_visible_treasures.empty?))
        return true
      else
        return false        
      end
    end
        
    def substract_visible_treasure(t)
      if(!death)
        for i in specific_visible_treasures 
          if(t.type == specific_visible_treasures.get(i))
            specific_visible_treasures.remove(i)
            break
          end
        end
      end 
    end  
        
    def substract_hidden_treasure(t)
      if(!death)
        for i in specific_hidden_treasures 
          if(t.type == specific_hidden_treasures.get(i))
            specific_hidden_treasures.remove(i)
            break
          end
        end
      end 
    end   
          
    def adjust_to_fit_treasure_lists(v, h)
      #DEVUELVE un BadStuff solo con los tesoros especificos que coinciden con los recibidos como parametros(los que tiene actualmente player) y lo que tiene el propio badstuff 
      t_visibles = Array.new
      t_ocultos = Array.new
      
      for i in v
        for j in @specific_visible_treasures
          if j == i.type
            t_visibles << j
            @specific_visible_treasures.delete(j)
          end          
        end
      end
      
      for i in h
        for j in @specific_hidden_treasures
          if j == i.type
            t_ocultos << j
            @specific_hidden_treasures.delete(j)
          end          
        end
      end

      return BadStuff.new_level_specific_treasures("", 0, t_visibles, t_ocultos)
    end
          
    def my_bad_stuff_is_death
      return @death      
    end
        
    def to_s
      "Texto: #{@text} \n Niveles perdidos: #{@levels} \n Tesoros visibles perdidos: #{@nVisibleTreasures} \n Tesoros ocultos perdidos: #{@n_hidden_treasures} \n Tesoros especificos visibles perdidos: #{@specific_visible_treasures} \n Tesoros especificos ocultos  perdidos: #{@specific_hidden_treasures} \n Muerte: #{@death}"
    end

    private #METODOS PRIVADOS
    def add_hidden(t)
      @specific_hidden_treasures << t;
    end

    def add_visible(t)
      @specific_visible_treasures << t;
    end
    
  end
end